function mnames = aft_MapNames(hfile)
% AFT::MapNames  - return a cell array (Nx1) of map names
%
% FORMAT:       mnames = obj.MapNames;
%
% No input fields.
%
% Output fields:
%
%       mnames      Nx1 list with map names
%
% TYPES: AVA, CMP, GLM, HEAD, SMP, VMP

% Version:  v0.8a
% Build:    9102119
% Date:     Oct-21 2009, 7:14 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, true)
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
sc = bvqxfile_getscont(hfile.L);
bc = sc.C;
ft = lower(sc.S.Extensions{1});

% switch over type
switch (ft)
    
    % AVA files
    case {'ava'}
        am = fieldnames(bc.Maps);
        nm = zeros(1, numel(am));
        for c = 1:numel(am)
            nm(c) = size(bc.Maps.(am{c}), 4);
        end
        mnames = cell(1, sum(nm));
        mc = 1;
        for c = 1:numel(am)
            if nm(c) ~= 1
                for cc = 1:nm(c)
                    mnames{mc} = sprintf('%s %d', am{c}, cc);
                    mc = mc + 1;
                end
            else
                mnames{mc} = am{c};
                mc = mc + 1;
            end
        end
        
    % CMP files
    case {'cmp'}
        mnames = {bc.Component(:).Name};
        
    % GLM files
    case {'glm'}

        % get map names
        mnames = {bc.Predictor(:).Name2};

        % for RFX GLMs, reorder
        if bc.ProjectTypeRFX > 0
            mnameo = reshape(1:(numel(mnames) - numel(bc.GLMData.Subject)), ...
                size(bc.GLMData.Subject(1).BetaMaps, ...
                ndims(bc.GLMData.Subject(1).BetaMaps)) - 1, ...
                numel(bc.GLMData.Subject));
            mnameo(end + 1, :) = (numel(mnameo) + 1):numel(mnames);
            mnames = mnames(lsqueeze(mnameo));
        end
        
    % AFNI HEAD/BRIK files
    case {'head'}
        mnames = {bc.Brick(:).Label};
        
    % SMP files
    case {'smp', 'vmp'}
        mnames = {bc.Map(:).Name};
        
    % default: 
    otherwise
        
        % give back filename without extension
        [fn{1:3}] = fileparts(sc.F);
        
        % but if empty, create name in <>
        if isempty(fn{2})
            fn{2} = sprintf('<interactive %s>', ft);
        end
        mnames = fn(2);
        
end

% linearize
mnames = mnames(:);
